/**
 * 
 */
package il.ac.bgu.cs.heuristics.utils;

import java.util.Set;
import java.util.Stack;

/**
 * @author haro
 * 
 */
public class StackSet<T> {
	Set<T>		set		= null;
	Stack<T>	stack	= null;

	public StackSet() {
		set = CollectionUtils.newLinkedHashSet();
		stack = CollectionUtils.newStack();
	}

	public boolean push(T item) {
		if (!set.add(item))
			return false;
		stack.push(item);
		return true;
	}

	public void pop() {
		if (!set.remove(stack.pop()))
			throw new IllegalArgumentException(
					"could not remove element from set");
	}

	public int size() {
		if (stack.size() != set.size())
			throw new IllegalArgumentException(
					"could not remove element from set");
		return stack.size();

	}
}
